cur_folder=$(shell pwd)

#INCDIRS += \
		$(cur_folder)
#INCLUDE	+=	$(patsubst %, -I %, $(shell pwd))

CFILES			:=  use_lib.c #$(wildcard *.c)
CPLUSPLUSFILES			:= $(wildcard *.cpp)
SO_NAME=libso_test.so

CC=gcc
CXX=g++
LIBPATH= -L./
# lib=-lpthread -lrt  -ldl -Wl,-rpath=./ -lso_test 
CPPFLAGS = -Wall -std=c++11
CFLAGS = -Wall -std=c11 


#LD_FLAGS = -Xlinker "-(" $(LIBS) -Xlinker "-)"  -L$(LIB_DIR) -Wl,-Map=$(TARGET).map -Wl,-gc-sections 



ifneq ("$(LINK)", "static")
else
LD_FLAGS +=  -static 
endif
STATIC_LINK_LIB  = static_lib_test2  pthread 
DYNAMIC_LINK_LIB  = dynamic_lib_test dl

RUNTIME_SO_PATH =./
LD_FLAGS +=-Wl,-rpath=$(RUNTIME_SO_PATH)

lib = -Wl,-Bstatic  $(addprefix -l, $(STATIC_LINK_LIB))  -Wl,-Bdynamic $(addprefix -l, $(DYNAMIC_LINK_LIB)) 

TARGET = so_test



COBJS :=$(patsubst %.c,  %.o,$(CFILES))
CPLUSPLUSOBJS :=$(patsubst %.cpp, %.o,$(wildcard *.cpp))
objs+=		\
	$(COBJS)  $(CPLUSPLUSOBJS)

all:$(objs)
	$(CC) $(LD_FLAGS) -o $(TARGET)   $^ $(LIBPATH) $(lib)  



%.o:%.c
	$(CC)	$(CFLAGS) $(INCLUDE)    -c  $<  -o $@ 
%.o:%.S
	$(CC)  $(CFLAGS) $(INCLUDE)	-c $<   -o $@ 
%.o:%.cpp
	$(CXX)  $(CPPFLAGS) $(INCLUDE)	   -c $<  -o $@ 

debug:
	@echo objs=$(objs)

.PHONY: clean  buildso debug
clean:	#.$$已在每次使用后立即删除。-f参数表示被删文件不存在时不报错
	rm -f  $(objs) $(so_objects) $(TARGET) 